package com.yztc.orangeentertainment;

import android.app.Activity;
import android.app.Application;

import com.litesuits.orm.LiteOrm;
import com.litesuits.orm.db.DataBaseConfig;
import com.yztc.orangeentertainment.config.ChannalDbConfig;

import java.util.ArrayList;

/**
 * Created by kang on 2016/10/4.
 */

public class App extends Application {
    private static LiteOrm liteOrm;
    private static App app;

    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
        if (liteOrm == null) {
            DataBaseConfig config = new DataBaseConfig(this, ChannalDbConfig.DB_NAME);
            config.dbVersion = 1;
            config.onUpdateListener = null;
            liteOrm = LiteOrm.newSingleInstance(this, ChannalDbConfig.DB_NAME);

        }
//        liteOrm.setDebugged(true); // open the log
    }

    public static App getApp() {
        return app;
    }

    public static LiteOrm getLiteOrm() {
        return liteOrm;
    }

    private static ArrayList<Activity> listOfActivity = new ArrayList<Activity>();

    public static void addActivity(Activity a) {
        listOfActivity.add(a);
    }

    public static void killActivity(Class<?> cls) {
        for (int i = 0; i < listOfActivity.size(); i++) {
            Activity activity = listOfActivity.get(i);
            if (activity.getClass().equals(cls)) {
                activity.finish();

            }
        }
    }
}